// ++++++++++++++++++++++++++++++++++++++++
// 《Go 语言+Vue.js 实战派——基于 Gin 框架》源码
// ++++++++++++++++++++++++++++++++++++++++
// 作者公众号：源码大数据
// 自媒体账号（抖音、视频号、快手、B站、知乎）：廖显东-ShirDon
// 仓库地址：https://gitee.com/shirdonl/goGinVue.git
// 仓库地址：https://github.com/shirdonl/goGinVue.git
// 博客：https://www.shirdon.com
// 购买图书：https: //item.jd.com/14958064.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
)

func main() {
	router := gin.Default()

	// 使用中间件
	router.Use(LoggerMiddleware())

	// 添加一个路由处理器
	router.GET("/", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "Hi~",
		})
	})

	router.Run(":8080")
}

func LoggerMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		fmt.Println(c.Request.Method)
		log.Printf("%s %s\n", c.Request.Method, c.Request.URL)
		c.Next()
	}
}

//GET
//2024/01/13 14:46:47 GET /
